﻿using System;
using System.IO;
using System.Windows.Forms;

namespace SceneUnpacker.se.gno
{
    internal class DragDropSupport
    {
        public event DropHandler Drop;

        public DragDropSupport(Control c, DropHandler handler)
        {
            c.DragEnter += new DragEventHandler(this.DragEnter);
            c.DragDrop += new DragEventHandler(this.DragDrop);
            this.Drop = (DropHandler) Delegate.Combine(this.Drop, handler);
        }

        public void DragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.SymbolicLink))
            {
                string[] data = (string[]) e.Data.GetData(DataFormats.FileDrop);
            }
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] strArray = (string[]) e.Data.GetData(DataFormats.FileDrop);
                this.Drop(new DirectoryInfo(strArray[0]));
            }
        }

        public void DragEnter(object sender, DragEventArgs e)
        {
            bool flag = false;
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] data = (string[]) e.Data.GetData(DataFormats.FileDrop);
                if (data.Length >= 1)
                {
                    DirectoryInfo info = new DirectoryInfo(data[0]);
                    if (info.Exists)
                    {
                        flag = true;
                    }
                }
            }
            if (flag)
            {
                e.Effect = DragDropEffects.Move | DragDropEffects.Copy | DragDropEffects.Scroll;
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }

        public delegate void DropHandler(DirectoryInfo dir);
    }
}

